import unittest

from common.case_automatic_control import TestCaseAutomaticGeneration
from tools.HTMLTestRunner import HTMLTestRunner
from common.path_setting import ensure_path_sep
import time
from config import config

# 加载用例集
# from estcases.test_goods import TestGoods
now_time = time.strftime('%Y%m%d%H%M%S', time.localtime())
case_automatic_switch = config.case_automatic_switch
if case_automatic_switch:
    TestCaseAutomaticGeneration().get_case_automatic()

testcases = unittest.defaultTestLoader.discover(start_dir=ensure_path_sep("\\testcases"), pattern='test*.py')
report_path = ensure_path_sep(f"\\outputs\\reports\\{now_time}_report.html")
with open(report_path, "wb+") as file:
    HTMLTestRunner(stream=file, title="测试报告").run(testcases)
# 执行用例，生产测试报告
